import { createRouter, createWebHistory } from 'vue-router'

import HomeVue from '@/views/articles/Home.vue'
import ArticlesVue from '@/views/articles/Articles.vue'
import ProfileVue from '@/views/user/Profile.vue'
import LoginVue from '@/views/user/Login.vue'
import LayoutVue from '@/views/Layout.vue' // 添加Layout组件导入
import ArticleFormVue from '@/views/articles/ArticlesFrom.vue' // 添加ArticleForm导入

const routes = [
  
  { 
    path: '/', 
    name:'路由布局', 
    component: LayoutVue, // 修改为Layout组件
    redirect: '/articles/home', // 默认跳转
    children: [
        { path: '/login', name: '登录', component: LoginVue },
        { path: '/user/profile', name: '个人中心', component: ProfileVue },
        { path: '/articles/home', name: '文章首页', component: HomeVue },
        { path: '/articles', name: '文章列表', component: ArticlesVue },
        // 修改文章编辑/新建路由，使id参数可选
        { path: '/articles/save/:id?', name: '编辑,新建文章', component: ArticleFormVue }, 
        
    ]
  },
  // 同时保留独立的登录路由
  { path: '/login', name: '登录(独立)', component: LoginVue },
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

export default router